using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Employers_company : System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
         WebConfigurationManager.ConnectionStrings[
           "Database2000"].ConnectionString;
        if (Session.Contents["rcuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            if (!IsPostBack)
            {
                btnSave.Text = "Update";
                EditInfo();
            }
            btnSave.Text = "Save";
        }
    }
    void EditInfo()
    {
        SqlServerProvider cls = 
        new SqlServerProvider(connectionString);
        cls.CommandText = "select RecruiterID, "+
        "ContactName, Address, City, "+
        "Convert(char(11),OpenDate, 101) "+
        "as OpenDate, Phone, Fax, Country," +
        "ProvinceID from  tblRCAccounts " +
        " where RecruiterID=@RecruiterID";
        cls.ParameterCollection = 
        new string[1] {"@RecruiterID"};
        cls.ValueCollection = new 
        string[1]{Session["rcuserid"].ToString()};
        DataTable dataTable =
        cls.GetDataTable();
        if (dataTable.Rows.Count > 0)
        {
            txtContact.Text = dataTable.Rows[0][1].ToString();
            txtAddress.Text = dataTable.Rows[0][2].ToString();
            txtCity.Text = dataTable.Rows[0][3].ToString();
            txtOD.Text = dataTable.Rows[0][4].ToString();
            txtTel.Text = dataTable.Rows[0][5].ToString();
            txtFax.Text = dataTable.Rows[0][6].ToString();
            txtCountry.Text = dataTable.Rows[0][7].ToString();
            ddlProvince.SelectedValue = dataTable.Rows[0][8].ToString();
           
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        SqlServerProvider cls = new SqlServerProvider(connectionString);
        if (!cls.UpdateCompany(Convert.ToString(
            Session.Contents["rcuserid"]),
            txtContact.Text,
            txtAddress.Text,
            txtCity.Text,
            txtTel.Text,
            txtFax.Text,
            txtCountry.Text,
            ddlProvince.SelectedValue,
            txtOD.Text))
            literalError.Text = "Error: " + cls.ErrorMessage;
        else
            Response.Redirect("thankyou.aspx");
    }
}
